package com.cloudxingkong.dianyinke.NewTeacher.Adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;

import com.cloudxingkong.dianyinke.R;

import java.util.List;

/**
 * Created by LeeQ on 2016-4-28.
 */
public class PostDTAdapter extends BaseAdapter {
    private Context context;
    private List<Bitmap> imgList;
    private boolean isDelete;

    public PostDTAdapter(Context context, List<Bitmap> imgList) {
        this.context = context;
        this.imgList = imgList;
    }

    @Override
    public int getCount() {
        return imgList.size()+1;
    }

    @Override
    public Object getItem(int position) {
        return imgList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = View.inflate(context, R.layout.item_post_gv, null);
        ImageView ivPic= (ImageView) convertView.findViewById(R.id.post_img_pic);
        FrameLayout postFrame= (FrameLayout) convertView.findViewById(R.id.post_frame_pic);

        if (imgList.size() >= 1) {
            if (position <= imgList.size() - 1) {
                postFrame.setVisibility(View.GONE);
                ivPic.setVisibility(View.VISIBLE);
                ivPic.setImageBitmap(imgList.get(position));
            }
        }
        return convertView;
    }

    public void remove(int position){
        Log.e("test","适配器中图片集合大小 "+imgList.size());
        imgList.remove(position);
        notifyDataSetChanged();
    }

}
